<?php
class system_passport_storage_session extends system_passport_storage_abstract {

	private $_session = null;
	public function __construct($namespance) {
		parent::__construct($namespance);
		$this->_session = new system_session_namespace($this->_namespace);
	}
	
	public function save() {
		$this->_session->{system_passport::$_name} = serialize($this->_data);
		$this->_session->lock();
		return $this;
	}
	
	public function clean() {
		if(isset($this->_session->{system_passport::$_name})) {
			unset($this->_session->{system_passport::$_name});
		}
		$this->_data = null;
		return $this;
	}
	
	public function readData() {
		if($this->_data === null) {
			$data = $this->_session->{system_passport::$_name};
			$this->_data = !empty($data) ? unserialize($data) : null;
		}
		return $this->_data;
	}
	
}